package com.chenju.invokechainservice;

import com.chenju.invokechainservice.adapter.ClassNodeAdapter;
import com.chenju.invokechainservice.adapter.MethodVisitorAdapter;
import com.chenju.invokechainservice.common.enums.ChangeType;
import com.chenju.invokechainservice.common.exceptions.FunnyException;
import com.chenju.invokechainservice.common.exceptions.FunnyFileNotFoundException;
import com.chenju.invokechainservice.domain.DiffMethodDetailEntity;
import com.chenju.invokechainservice.domain.DiffMethodEntity;
import com.chenju.invokechainservice.domain.TAopMethod;
import com.chenju.invokechainservice.service.*;
import com.chenju.invokechainservice.service.impl.TClassNodeServiceImplement;
import com.chenju.invokechainservice.test.TestAop;
import com.chenju.invokechainservice.utils.FunnyFileUtils;
import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.comments.Comment;
import com.github.javaparser.symbolsolver.JavaSymbolSolver;
import com.github.javaparser.symbolsolver.resolution.typesolvers.ClassLoaderTypeSolver;
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver;
import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver;
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
import com.google.common.collect.Lists;
import org.junit.jupiter.api.Test;
import org.objectweb.asm.ClassReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.CollectionUtils;


import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.chenju.invokechainservice.utils.GitRepositoryComparator.generateDiffFileMap;

@SpringBootTest
class InvokechainServiceApplicationTests {
    @Autowired
    private TMethodNodeService tMethodNodeService;
    @Autowired
    private TClassNodeService tClassNodeService;
    @Autowired
    private JavaParserService javaParserService;
    @Autowired
    private FunnyTestService funnyTestService;

    @Test
    void contextLoads() {
    }

    void testParseProjectToNode() throws IOException {
        String codePath = "D:\\Project\\testgit\\master";
        tClassNodeService.parseProjectToNode(codePath);
    }

    @Autowired TestAop aop;

    @Test
    void testAOP() {
        String method = aop.findMethod();
        System.out.println(method);
    }

    @Autowired
    private TAopService tAopService;

    @Test
    void testMybatis() {
//        List<String> adviceForMethods = new ArrayList<>();
//        adviceForMethods.add("method1");
//        adviceForMethods.add("method2");
//        TAopMethod entity = new TAopMethod("findByName", "Before", "@annotation()");
//        entity.setAdviceForMethods(adviceForMethods);
//        tAopService.saveAopMethod(entity);
//
        TAopMethod aopMethod = tAopService.findAopMethodByMethodName("findByName");
        System.out.println(aopMethod.getAdviceForMethods() instanceof List);
    }

    @Test
    void testBeanClass(){
        String codePath = "D:\\Project\\springboot-easytest";
//        tAopService.parseProjectPointcut(codePath);
        Map<String, File> springBeanClassMap = tAopService.findSpringBeanClassMap(codePath);
        System.out.println(springBeanClassMap);
    }
}
